#ifndef MQTTHANDLER_H
#define MQTTHANDLER_H

#include <QObject>
#include "mqtt/qmqtt.h"

class MqttHandler : public QObject
{
    Q_OBJECT
public:
    explicit MqttHandler(QObject *parent = 0);
    void connectToHost();//连接函数
    void setHost(const QHostAddress& host){client->setHost(host);}//设置地址
    void setPort(const quint16 port){client->setPort(port);}//设置端口

signals:
    void dataUpSignal(const QByteArray &);//更新信号
    void ctrlUpSignal(const QByteArray &);//控制信号

public slots:
    void doConnected();//建立连接
    void doSubscribed(const QString& topic, const quint8 qos);//订阅函数
    void doDataReceived(QMQTT::Message message);//接受数据
    void detectState();
    quint16 publish(const QMQTT::Message& message);

private:
    QMQTT::Client *client;
};

#endif // MQTTHANDLER_H
